Stub Article
This article needs more information, clarification, or completion.
You can help us by expanding this article. There may be more information on its talk page.


This page is about custom blocks. For How to Add Block Help to Custom Blocks, see How to Add Block Help to Custom Blocks.
Custom Blocks are blocks which are not primitive but are rather made by using primitive or other custom blocks. The ability of making custom blocks is one of the main features of Snap! and was the main feature of BYOB (BYOB stands for Build Your Own Blocks). You can make your own commands, reporters, and predicates with this feature. However, it is not possible to make custom hat blocks, even though they have easy workarounds, such as the when <> block.

Making Custom Blocks

Naming Custom Blocks

To make custom blocks, you need to write a name for it at first. This article will show you how to make a block that will make sprites bounce. Click the Make a Block button to write the name for your custom block.

Naming a custom block

Coding or Programming Custom Blocks

Your custom blocks will not do anything if there is no code for it. After all, it will work like a seperate program. As such, you must use other blocks to make it. For this block, you will have to insert this code- point in direction ((direction) - (180))

Code for Bounce Block

Inputs

In case you want the results to vary (say you want squares of different size), click the plus symbols (if you turn on Plain prototype labels, you may need to wait for it to appear). You will now get the option to name an input. If you click the small arrow next to "Input name", you'll get a lot of options. Clicking the cog icon, you should see a little more options. You also get the choice to have a single input or multiple inputs.

InputUsed forExample Use
ObjectCostumes, sounds, sprites(copy of costume @turtle :: looks)
TextPlain text, not anything elseerror [Error!] :: control
ListLists(@flash assoc @list :: list)
NumberNumbers, not textmove (10) steps
Any typeAnythingsay []
Boolean (T/F)True or false<not <>>
Command (inline)Command block ring
ReporterReporter ring(multimap (() @addInput) over @list @delInput @verticalEllipsis @addInput :: list)
PredicatePredicate ring(sort @list using (<> @addInput) :: list)
Command (C-shape)

((#)) for ((item)) in @list { } :: list

Any (unevaluated)(if <> then [] else [])
Boolean (unevaluated)

repeat until <> { }

Upvars

You can also put upvars into your blocks. Upvars are variables that can be accessed both inside and outside the block. It can be used to make commands that can report.

An example of a block that has an upvar:

for ((i)) = (1) to (10) {
}

More options

If you click "options", you can type the options that will be available in a dropdown.

If you click "read only", the input will be darker and you can't type in, blocks must be inserted in.

If you click "static", blocks cannot be inserted into that input.

Menus

Menus gives various options that change by itself automatically.

MenuIncludesExample Use
messagesBroadcastsbroadcast [ V] @addInput
objectsAll the sprites and stage, excluding itself(object [ V])
data types[upcoming in 10.0]List of data types, such as text, numbers and procedures<is [] a [number V] ?>
costumesThe costumes that the sprite hasswitch to costume [ V]
soundsThe sounds that the sprite hasplay sound [ V]
variablesset [ V] to []
piano keyboardShows a piano keyboard that you use to select a note.play note (60 v) for () beats
360° dialA dial for selecting a direction.point in direction ( v)
destinations[upcoming in 10.0]Possible destinations that a sprite can go to, includes a random position, the mouse-pointer and the centergo to [ V]
locations[upcoming]Mouse-pointer, myself, other sprites
keys[upcoming]Keyboard keys<key [ V] pressed?
objects + self[upcoming]
sprites + self[upcoming]
collidables[upcoming]Mouse-pointer, edge, pen trails and other sprites<touching [ V] ?
object attributes[upcoming](my [ V])
properties[upcoming]
scenes[upcoming]switch to scene [ V] @addInput
microphone[upcoming]Microphone properties(microphone [ V])
primitives[upcoming]Primitive functions
extensions[upcoming]Extension functionsextension [ V] [] @delInput @verticalEllipsis @addInput
Special

If you click special, you get special inputs.

InputDescriptionExample Use
multi-lineText input that allows multiple lines

(multiline [Hello world] :: operators)

codeUsed for anything related to code, functions the same as multi-line but monospace
color[upcoming](color [#ff0000] :: pen)
variables[upcoming]Multiple upvarsscript variables ((a)) @addInput
receivers[upcoming]Expands to "to _", then "to _ with data"broadcast [ V] @addInput
send data[upcoming]Like receivers, but the broadcast dropdown is not read-only. Intended for cross-scene broadcasts.
conditionals[upcoming]Can be expanded into C-shape branches with Booleans